package com.hyg.lib_common.DataModel.Music;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.Objects;

public class Music implements Parcelable {

    public int id;
    public String musicName;//歌曲名
    public String musician;
    public int musicDuration;
    public int region;
    public String musicUrl;//歌曲地址
    public int cateId;
    public String cateName;

    //扩展属性
    public boolean isWhite;
    public boolean isFav;
    public boolean isPlaying=false;

    public boolean isChecked=false;
    public boolean isEditable=false;

    public int parentType = 0;    //音乐类型    0 乐库   1 养生定制音乐  2 睡眠定制音乐 3 解压定制音乐      换一换必须参数
    public int sleepMusicType = 0;  //助眠模块小分类    0：音乐疗愈类型非助眠，1：15分钟，2：20分钟，3：40分钟    换一换必须参数
    public String testResult;   //测试问卷结果    详情页查看结果需要参数


    public Music(int id, String musicName, String musician, int musicDuration, int region, String musicUrl, int cateId, String cateName, boolean isWhite, boolean isFav) {
        this.id = id;
        this.musicName = musicName;
        this.musician = musician;
        this.musicDuration = musicDuration;
        this.region = region;
        this.musicUrl = musicUrl;
        this.cateId = cateId;
        this.cateName = cateName;
        this.isWhite = isWhite;
        this.isFav = isFav;
    }

     public Music(int id, String musicName, String musician, int musicDuration, int region, String musicUrl,
                  int cateId, String cateName, boolean isWhite, boolean isFav,
     int parentType,int sleepMusicType,String testResult
     ) {
        this.id = id;
        this.musicName = musicName;
        this.musician = musician;
        this.musicDuration = musicDuration;
        this.region = region;
        this.musicUrl = musicUrl;
        this.cateId = cateId;
        this.cateName = cateName;
        this.isWhite = isWhite;
        this.isFav = isFav;

        this.parentType=parentType;
        this.sleepMusicType=sleepMusicType;
        this.testResult=testResult;
    }

      public Music(int id, String musicName, String musician, int musicDuration, int region, String musicUrl,
                   boolean isFav,
                int parentType,int sleepMusicType,String testResult,boolean isPlaying,boolean isChecked,boolean isEditable
     ) {
        this.id = id;
        this.musicName = musicName;
        this.musician = musician;
        this.musicDuration = musicDuration;
        this.region = region;
        this.musicUrl = musicUrl;
        this.isFav = isFav;

        this.parentType=parentType;
        this.sleepMusicType=sleepMusicType;
        this.testResult=testResult;

        this.isPlaying=isPlaying;
        this.isChecked=isChecked;
        this.isEditable=isEditable;
    }


    protected Music(Parcel in) {
        id = in.readInt();
        musicName = in.readString();
        musician = in.readString();
        musicDuration = in.readInt();
        region = in.readInt();
        musicUrl = in.readString();
        cateId = in.readInt();
        cateName = in.readString();
        isWhite = in.readByte() != 0;
        isFav = in.readByte() != 0;
        isPlaying = in.readByte() != 0;
        isChecked = in.readByte() != 0;
        isEditable = in.readByte() != 0;
        parentType = in.readInt();
        sleepMusicType = in.readInt();
        testResult = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(musicName);
        dest.writeString(musician);
        dest.writeInt(musicDuration);
        dest.writeInt(region);
        dest.writeString(musicUrl);
        dest.writeInt(cateId);
        dest.writeString(cateName);
        dest.writeByte((byte) (isWhite ? 1 : 0));
        dest.writeByte((byte) (isFav ? 1 : 0));
        dest.writeByte((byte) (isPlaying ? 1 : 0));
        dest.writeByte((byte) (isChecked ? 1 : 0));
        dest.writeByte((byte) (isEditable ? 1 : 0));
        dest.writeInt(parentType);
        dest.writeInt(sleepMusicType);
        dest.writeString(testResult);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<Music> CREATOR = new Creator<Music>() {
        @Override
        public Music createFromParcel(Parcel in) {
            return new Music(in);
        }

        @Override
        public Music[] newArray(int size) {
            return new Music[size];
        }
    };

    //重写equals方法, 使得可以用contains方法来判断列表中是否存在Music类的实例
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Music music = (Music) o;
        return Objects.equals(musicName, music.musicName);
    }

    @Override
    public String toString() {
        return "Music{" +
                "id=" + id +
                ", musicName='" + musicName + '\'' +
                ", musician='" + musician + '\'' +
                ", musicDuration=" + musicDuration +
                ", region=" + region +
                ", musicUrl='" + musicUrl + '\'' +
                ", cateId=" + cateId +
                ", cateName='" + cateName + '\'' +
                ", isWhite=" + isWhite +
                ", isFav=" + isFav +
                ", isPlaying=" + isPlaying +
                '}';
    }
}
